/**
 * Created by admin on 2017/9/25.
 */
define([
    "helpers/network"
], function (Network) {

    var goodsCategories = [];
    var goodsSuppliers = [];
    var goodsTypes = [{id:1,value:"实物"},{id:2,value:"话费"},{id:3,value:"京东E卡"}];

    function fetchGoodsCategories(callback) {
        var obj = {
            params: {
                type: "GoodsCategory"
            },
            sort: ["creationTime,desc"],
            all: true
        };
        Network.ajax("/BizView.queryAll.query", obj, function (ret) {
            var gc = [];
            _.forEach(ret.data.content, function (each) {
                gc.push(each.data)
            });
            this.goodsCategories = gc;
            if (callback) {
                callback(ret)
            }
        }.bind(this));
    }

    function fetchGoodsSuppliers(callback) {
        var obj = {
            params: {
                type: "GoodsSupplier"
            },
            sort: ["creationTime,desc"],
            all: true
        };
        Network.ajax("/BizView.queryAll.query", obj, function (ret) {
            var gs = [];
            _.forEach(ret.data.content, function (each) {
                gs.push(each.data)
            });
            this.goodsSupplier = gs;
            if (callback) {
                callback(ret)
            }
        }.bind(this));
    }
    return {
        fetchGoodsCategories: fetchGoodsCategories,
        fetchGoodsSuppliers: fetchGoodsSuppliers,
        goodsCategories: goodsCategories,
        goodsSuppliers:goodsSuppliers,
        goodsTypes:goodsTypes
    };
});